package edu.mse.camel.client.chat.actions;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.List;

import edu.mse.camel.client.chat.message.IMessage;
import edu.mse.camel.client.chat.message.MessageList;

public class SaveChat {

	public void save(String filename){
				
		try{
			FileWriter fstream = new FileWriter(filename);
			BufferedWriter out = new BufferedWriter(fstream);
			
			List<IMessage> messages = MessageList.getInstance().getMessages();
			for(IMessage aMessage : messages)
			{
				out.write(aMessage.getName() + '\t');
				out.write(aMessage.getTimeStamp() + '\t');
				out.write(aMessage.getContent());
				out.write(System.getProperty("line.separator"));
			}
			out.close();
		}
		catch (Exception e){
			System.err.println("Error:" + e.getMessage());
		}
		
	}
}
